<style>
    label.error {
        background: url(<?=base_url()?>assets/img/backgrounds/errortop.png) no-repeat scroll left top #990000;
        color: #FFFFFF;
        display: block;
        font-size: 11px;
        margin: 8px 0 0;
        padding: 6px;
        width: 400px;
    }
    input.error, select.error {
        border: 1px dotted #C53436;
    }
    .ValidationAllErrors {
        background: #FFF;         
        border: 2px solid #990000;
        color: #990000;
        display: block;
        font-size: 11px;
        font-weight: bold;
        margin: 0 0 8px 0;
        padding: 4px;
    }
</style>
<?
    if(($form == 'edit')&&(!$validate)){
        foreach($vest as $row){
            $vest_id = $row->id;
            $title = $row->title ;
            $text = $row->text;
            $lang_id = $row->lang_id;
            $status = $row->status;
            $account_id = $row->account_id;
            $foto_path = $row->foto_path;
        }                                
    }           
?>
<a id="cc" style="display: none;">Click</a>
<script>
    $('#cc').live('click',function(){
        console.time('validate_form_anketa');
        var result =validate_form_anketa();    
        console.timeEnd('validate_form_anketa');
        alert(result)
        return false;
    })
</script>

<div id="heading">
    <div id="headinginner">
        <h1><span><?
                    if ($form == 'edit') { 
                        echo $title;
                    }else echo 'Naslov vijesti';
                ?>
            </span></h1>

        <p class="clear"></p>
    </div>
    <div id="stage-inner">
        <div id="validation_errors"><?php echo validation_errors('<div class="ValidationAllErrors">', '</div>'); ?></div>
        <?
            if ($form == 'edit') { 
            ?>
            <form action="<?=base_url()?>vesti/uredi_vesti/editvest" name="editVest" id="editVest" method="post"> 
            <?
            }else{
            ?>
            <form action="<?=base_url()?>vesti/uredi_vesti/createavest" name="editVest" id="editVest" method="post">
                <?
                }
            ?>                     

            <!--POOL NAME-->
            <div class="box nopadding">
                <div class="forminner">

                    <div style="width: 978px;" class="left">
                        <h4>Naslov vijesti</h4>
                        <input type="text" value="<? if (($form == 'edit')&&(!$validate)) echo $title; ?><?php echo set_value('title'); ?>" name="title" maxlength="160" style="width: 923px;" class="elmbigred" id="title">
                        <div id="question_error" class="ValidationErrors" style="display: none;"></div>
                        <?php echo form_error('title'); ?>

                        <div class="dividersmall2"></div>
                        <div class="left" id="server-foto" style="display: none;">
                            <h5 class="left" style="font-weight: bold;">Foto: </h5>
                            <span id="f_id" class="left" style="color: #888;"></span>
                            <ul class="navcontrol left">
                                <li style="padding: 0pt 5px 5px 10px;"><a id="delete-server-foto" href="javascript:void(0)" class="single" style="background-position: 9px -328px;">Ukloni fotografiju</a></li>
                                <?
                                    if($this->session->userdata('user') == "adriaex@t-com.me"){
                                    ?>
                                    <li style="padding: 0 0 5px;"><a id="thumb-server-foto" href="javascript:void(0)" class="single" style="background-position: 9px -119px;">Kreiraj thumbnail</a></li>
                                    <?   
                                    }
                                ?>

                            </ul>
                            <p class="clear"></p> 
                        </div>
                        <ul style="padding: 0pt 45px 0pt 0pt;" class="navcontrol right">
                            <li><a class="single linkmedia popup media" href="javascript:void(0)">Dodaj fotografiju</a></li>
                        </ul>

                        <p class="clear"></p>

                    </div>

                    <p class="clear"></p>
                </div> 
            </div>
            <!--END POOL NAME--> 

            <div class="dividersmall"></div>

            <!--POOL ANSWER-->
            <div class="box nopadding">
                <div class="forminner">
                    <div class="answersinsert">
                        <div class="answers" style="padding: 0;">
                            <div>
                                <textarea rows="25" cols="80" id="text" name="text" style="padding: 5px 15px; width: 100%" class="tinymce"><?if(($form == 'edit')&&(!$validate)){ echo $text;}else if($validate){echo set_value('text');}?></textarea>
                            </div>  
                        </div>

                        <div class="answerserror"> 
                            <div class="ValidationErrors" style="width: 400px; margin: 8px 0 0 60px; display: none;" id="erroranswertext">Molimo unestite najmanje 2 odgovora.</div>
                        </div>
                        <div class="answerserror" style="margin:0 18px 19px 60px;">
                            <?php echo form_error('text'); ?>  
                        </div>

                        <div class="qoptions nopadding">  
                            <div class="group noborder" style="padding-bottom: 20px;">
                                <div class="labelgroup">   
                                    <div class="checkbox">
                                        <input type="checkbox" value="1" id="status" name="status" <?if(($form == 'edit')&&(!$validate))if($status==1){echo'checked="checked"';}?><?php if (isset($status))if($status==1){echo'checked="checked"';}?>>
                                    </div>
                                    <label for="status">Objavite vijest na sajtu</label>
                                    <p class="clear"></p>
                                </div>
                            </div>

                            <p class="clear"></p>

                        </div>
                    </div>

                </div>
            </div> 
            <!--END POOL ANSWER-->       

            <div class="divider"></div>

            <!--POOL SUBMIT-->
            <div class="qoptions qoptionssmlbuttons">  
                <div class="right">
                    <input type="hidden" value="<? if($form == 'edit') echo $vest_id;?>" name="vest_id">
                    <input type="hidden" value="<? if(($form == 'edit')&&(!$validate)) echo $foto_path;?><? if(isset($_foto)) echo $_foto;?>" name="_foto" id="_foto">
                    <input type="hidden" value="1" name="custom_validation" />
                    <input type="submit" value="<? if($form == 'edit'){echo 'Uredi vijest';}else echo'Kreiraj vijest';?>" class="button">

                    <p class="clear"></p>
                </div>
                <p class="clear"></p>
            </div>
            <!--END POOL SUBMIT-->
        </form>

        <?
            if(($form == 'edit')&&(!$validate)){
                if($foto_path==""){

                }else{                   
                ?>
                <script>
                    $('#server-foto').css('display','block');
                    $('#f_id').html('<?=$foto_path?>');
                </script>
                <?
                }
            }
        ?>
        <? if((isset($_foto))&&($_foto!='')){
            ?>
            <script>
                $('#server-foto').css('display','block');
                $('#f_id').html('<?=$_foto?>');
            </script>
            <?
            }
        ?>
        <p class="clear"></p>
    </div>
</div>

<script type="text/javascript" charset="utf-8">
    jQuery( document ).ready(function() { 
        $('#delete-server-foto').live('click', function(){
            $('#_foto').val(""); 
            $('#server-foto').fadeOut();           
        })
        $('#thumb-server-foto').live('click', function(){
            var path= "assets/upload/fotografije/";
            var file= $('#_foto').val();
            $.ajax({
                type: 'POST',
                url: base_url+'img_manipulation/resize',
                dataType: 'json',
                data:({
                    path:path, 
                    file:file, 
                    width:90, 
                    height:65
                }),
                success: function(data){
                    if(data.success=='failed'){
                        alert('Nešto nije u redu.')
                    }else{
                        alert('Uspješno ste kreirali thumbnail.') 
                    }
                },
                error:function(data){alert("Error: " + data);}
            });

        })
        $('#close-dialog').live('click',function(){$.modal.close();});        
    });
</script>
<div id="media-modal" style="display: none;">
    <div id="poll-status-holder" class="dialog">
        <div class="body">
            <div class="title" id="status-title">Dialog za prenos fajlova</div>
            <div class="text">
                <p id="status-text">
                    Podržani formati su: *.jpg, *.png, *.gif.<br />
                    Dimenzije fotografije trebaju odgovariti dimenzijama na sajtu. <br />
                    <b>

                        <?

                            switch($this->session->userdata('user')){

                                case 'adriaex@t-com.me':        echo '418x190px'; break;                             

                                case 'busterminal@t-com.me':    echo '410x260px'; break;
                            }

                        ?>

                        <script type="text/javascript">

                            account_user =  '<?=$this->session->userdata("user");?>';

                            switch (account_user){

                                case 'adriaex@t-com.me':
                                    acimg_width = 418;
                                    acimg_height = 190;
                                    break;

                                case 'ikukic@yahoo.com':
                                    acimg_width = 410;
                                    acimg_height = 260;
                                    break;


                            }
                        </script>

                    </b>.
                </p>
                <div id="file-uploader-form">              
                </div>

                <script>        
                    function createUploader(){            
                        var uploader = new qq.FileUploader({
                            element: document.getElementById('file-uploader-form'),
                            action: base_url+'application/libraries/php.php',
                            debug: true,
                            onComplete: function(id, fileName, responseJSON){



                                var path= "assets/upload/fotografije/";
                                var file= $('#_foto').val();

                                $.ajax({
                                    type: 'POST',
                                    url: base_url+'img_manipulation/resize',
                                    dataType: 'json',
                                    data:({
                                        path:path, 
                                        file:responseJSON.filename, 
                                        width:acimg_width, 
                                        height:acimg_height
                                    }),
                                    success: function(data){

                                        if(data.success=='failed'){

                                            alert('Nešto nije u redu.')

                                        }else{

                                            var content = 'Prenos fajla uspješno završen.';
                                            $('#status-text') .html(content);  
                                            $('#server-foto').css('display','block');

                                            $('#_foto').val(data.new_image_name);
                                            $('#f_id').html($('#_foto').val());  

                                        }

                                    },
                                    error:function(data){alert("Error: " + data);}

                                });
                            }
                        });           
                    }

                    // in your app create uploader as soon as the DOM is ready
                    // don't wait for the window to load  
                    window.onload = createUploader;
                </script>                              
            </div>
        </div>

        <div class="controls">
            <div class="right">
                <a href="javascript:void(0)" class="plain custom-styles-done" id="close-dialog">Zatvori</a>
                <p class="clear"></p>
            </div>
            <p class="clear"></p>
        </div> 
    </div>
</div>
